package com.dfd.security.config.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/*
 *文件名: UserDetailsServiceImpl
 *创建者: 东东
 *创建时间:2021/9/2 14:36
 *描述:   自定义认证逻辑
 */
@Slf4j
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("登录用户名:" + username);
        //该User类是SpringSecurity自带实现UserDetails接口的一个用户类
        //使用加密工具对密码进行加密
        //其第三个属性为用户权限,后续说明
        return new User(username, passwordEncoder.encode("123456")
                , AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
        //第三个参数为是否可用，第四个参数为账户是否过期，第五个参数为密码是否过期，第六个参数为账户是否被锁定
        //其第七个属性为用户权限
//        return new User(username, passwordEncoder.encode("123456")
//                , true, true, true, false
//                , AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
